function json_result(req) 
{
	if (req.responseText.match(/^<html/))
	{
		Output.display(req.responseText)
		return null
	}

	eval("var result = " + req.responseText)
	return result
}

function isMac()
{
	return (navigator.userAgent.match(/Mac/) ? true : false)
}

function observeClick(div, callback)
{
	Event.observe(div, 'click', function (e) {
		callback.call(e)
		e.stopPropagation()
	})
}

Cookie =
{
	set: function (name, value, daysToExpire)
	{
		var expire = ''
		if (daysToExpire != undefined) {
			var d = new Date()
			d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)))
			expire = '; expires=' + d.toGMTString()
		}
		return (document.cookie = escape(name) + '=' + escape(value || '') + expire)
	},

	get: function (name)
	{
		var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'))
		return (cookie ? unescape(cookie[2]) : null)
	},

	destroy: function (name)
	{
		var cookie = Cookie.get(name) || true
		Cookie.set(name, '', -1)
		return cookie
	}
}

function toggle_hover(element)
{
	// assumes an image/input or an <a><img></a> layout
	var img = (element.type == 'image') ? element : element.firstChild
	var src = img.src
	if (src.match(/_hover/))
		img.src = src.replace(/_hover/, '')
	else
		img.src = src.replace(/\.(gif|png|jpg|jpeg)/, '_hover.$1')
}

HerokuAjax = {
	defaultOptions: {
		on410: function() {
			document.location = 'http://' + FaceHost + '/myapps'
		},
		on500: function() {
			alert("We're sorry, but something went wrong.  We've been notified about this issue and we'll take a look at it shortly.\n\nTry again, or try reloading the page.")
		}
	}
}
HerokuAjax.Request = function (url, options) {
	options = Object.extend(Object.clone(this.defaultOptions), options)
	return new Ajax.Request(AjaxPrefix + url, options)
}
HerokuAjax.Updater = function (container, url, options) {
	options = Object.extend(Object.clone(this.defaultOptions), options)
	return new Ajax.Updater(container, AjaxPrefix + url, options)
}
